<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %> 
<%@ page import="java.util.Date" %> 
<%@ page import="java.text.DateFormat" %> 
<%@ page import="java.text.SimpleDateFormat" %> 

<%
	
	try 
	{
 
		String connectionURL = "jdbc:mysql://localhost:3306/unilearn";
 
		int row_count = 0;
		Boolean check_flag = false;
		Connection connection = null;
		ResultSet rs=null;
		Statement stmt = null;
		
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		connection = DriverManager.getConnection(connectionURL, "root", "");
		stmt = connection.createStatement();
 
		if(!connection.isClosed())
		{
			String subject_id = "2";//request.getParameter("subject_id");
			String _desc = "";
			String _mark = "";
			String str_tableCount = request.getParameter("datTableCount");
			String str_assignment_id = request.getParameter("cboAssignmentList");
			int table_count = Integer.parseInt(str_tableCount);
			int _assignment_id = Integer.parseInt(str_assignment_id);
			//Double mark = Double.parseDouble(_mark);
	
			for(int i = 0; i < table_count; i++)
			{
				_desc = request.getParameter("txtDesc" + i);
				_mark = request.getParameter("txtMark" + i);	

				out.println("INSERT INTO assignment_marking_scheme (desc, maxScore , assignment_id)" 
				+ "VALUES ('"+_desc+"', '"+_mark+"', "+_assignment_id+")");
				
				row_count = stmt.executeUpdate("INSERT INTO assignment_marking_scheme (scheme_desc, maxScore , assignment_id)" 
				+ "VALUES ('"+_desc+"', '"+_mark+"', "+_assignment_id+")");
				
				if(row_count <= 0){
					check_flag = true;
					break;
				}
			}
			
			if(!check_flag)
				out.println( "<script>alert('Create Successful')</script>" );
			else
				out.println( "<script>alert('Create Failed')</script>" );
				
			response.sendRedirect("main_page.jsp");
		}
	}catch(Exception ex){
		out.println(ex);
	}
%>